/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * directHTMLPrintable.java
 *
 * Created on 15/12/2010, 04:51:51 PM
 */
package ibusplus.com.pe.jPrintApplet.gui;

import ibusplus.com.pe.jPrintApplet.ee.HTMLPrinter;
import java.awt.print.PrinterJob;
import javax.print.PrintService;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;

/**
 *
 * @author Emmanuel
 */
public class directHTMLPrintable extends javax.swing.JApplet {

    /** Initializes the applet directHTMLPrintable */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {

                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 71, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    private JEditorPane ePanel = new JEditorPane();
    private String htmlText = "";

    public void setHtmlText(String htmlText) {
        this.htmlText = htmlText;
    }

    public void printHtmlContent() {
        ePanel.setContentType("text/html");
        ePanel.setText(htmlText);
        HTMLPrinter target = new HTMLPrinter();
        PrinterJob printJob = PrinterJob.getPrinterJob();
        PrintService printer = printJob.getPrintService();
        if (printer == null) {
            JOptionPane.showMessageDialog(this, "No se econtró impresora", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
        try {
            target.print(ePanel);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getCause(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
